package cn.jhg.account.rest;

import java.sql.Timestamp;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import cn.jhg.account.entity.MaterialBatch;
import cn.jhg.account.service.MaterialBatchSvc;
import cn.jhg.account.util.ServiceResult;
@Component
public class MaterialBatchRestImpl implements MaterialBatchRest {
	@Resource
	private MaterialBatchSvc materialBatchSvc;
	
	/**
	 * 新增原料批次
	 * @param batch	批次实体
	 * @return	ServiceResult<Integer>	批次id，ErrorCode
	 */
	@Override
	public ServiceResult<Integer> addBatch(int codeId, String batchNo, int manuId, int statId, String propId,
			Timestamp expDate, Timestamp inspDate) {
		MaterialBatch batch = new MaterialBatch();
		batch.setCodeId(codeId);
		batch.setBatchNo(batchNo);
		batch.setManuId(manuId);
		batch.setStatId(statId);
		batch.setPropId(propId);
		batch.setExpDate(expDate);
		batch.setInspDate(inspDate);
		ServiceResult<Integer> result = materialBatchSvc.addBatch(batch, 1, 1);
		return result;
	}

	/**
	 * 更新原料批次
	 * @param batch 批次实体
	 * @return	ServiceResult<Object>	ErrorCode
	 */
	@Override
	public ServiceResult<Object> updateBatch(int id, int codeId, String batchNo, int manuId, int statId, String propId,
			Timestamp expDate, Timestamp inspDate) {
		MaterialBatch batch = new MaterialBatch();
		batch.setId(id);
		batch.setCodeId(codeId);
		batch.setBatchNo(batchNo);
		batch.setManuId(manuId);
		batch.setStatId(statId);
		batch.setPropId(propId);
		batch.setExpDate(expDate);
		batch.setInspDate(inspDate);
		ServiceResult<Object> result = materialBatchSvc.updateBatch(batch, 1, 1);
		return result;
	}

	/**
	 * 删除原料批次
	 * @param id	批次id
	 * @return	ServiceResult<Object>	ErrorCode
	 */
	@Override
	public ServiceResult<Object> deleteBatch(int id) {
		ServiceResult<Object> result = materialBatchSvc.deleteBatch(id, 1, 1);
		return result;
	}

	/**
	 * 根据id查询原料批次
	 * @param id	批次id
	 * @return	ServiceResult<MaterialBatch>	批次实体，ErrorCode
	 */
	@Override
	public ServiceResult<MaterialBatch> queryBatchById(int id) {
		ServiceResult<MaterialBatch> result = materialBatchSvc.queryBatchById(id, 1);
		return result;
	}

	/**
	 * 查找原料批次
	 * @param batchNo	批次号	
	 * @param manuName	生产厂名称
	 * @param statId	状态代码
	 * @return	ServiceResult<List<Integer>>	批次id集合，ErrorCode
	 */
	@Override
	public ServiceResult<List<Integer>> findBatch(String batchNo, String manuName, int statId) {
		ServiceResult<List<Integer>> result = materialBatchSvc.findBatch(batchNo, manuName, statId, 1);
		return result;
	}

	/**
	 * 查找批次详细信息
	 * @param batchNo	批次号
	 * @param manuName	生产厂名称
	 * @param statId	状态代码
	 * @return	ServiceResult<List<MaterialBatch>>	批次实体集合，ErrorCode
	 */
	@Override
	public ServiceResult<List<MaterialBatch>> findBatchDetail(String batchNo, String manuName, int statId) {
		if(null==batchNo){
			batchNo="";
		}
		if(null==manuName){
			manuName="";
		}
		ServiceResult<List<MaterialBatch>> result = materialBatchSvc.findBatchDetail(batchNo, manuName, statId, 1);
		return result;
	}

	/**
	 * 检查批次有效期
	 * @param timestamp	时间戳
	 * @return	ServiceResult<List<Integer>>	有效期超过 timestamp 所指定时间的批次id集合 ，ErrorCode
	 */
	@Override
	public ServiceResult<List<Integer>> checkExpiredDate(Timestamp timestamp) {
		ServiceResult<List<Integer>> result = materialBatchSvc.checkExpiredDate(timestamp, 1);
		return result;
	}

	/**
	 * 检查批次复检期
	 * @param timestamp	时间戳
	 * @return	ServiceResult<List<Integer>>	复检期超过 timestamp 所指定时间的批次id集合，ErrorCode
	 */
	@Override
	public ServiceResult<List<Integer>> checkInspectionDate(Timestamp timestamp) {
		ServiceResult<List<Integer>> result = materialBatchSvc.checkInspectionDate(timestamp, 1);
		return result;
	}

}
